package com.example.summary.lianbiao;

/**
 * Created by wzn on 2019/3/28.
 */
public class LianbiaoHuan {

    /**
     * 1 2 3   7
     * 4 5 6
     *
     * @param args
     */
    public static void main(String[] args) {

        LianBiaoNode one = new LianBiaoNode(1, null);
        LianBiaoNode two = new LianBiaoNode(2, null);
        LianBiaoNode three = new LianBiaoNode(3, null);
        LianBiaoNode four = new LianBiaoNode(4, new LianBiaoNode(5, new LianBiaoNode(6, new LianBiaoNode(7, three))));
        one.setNext(two);
        two.setNext(three);
        three.setNext(four);


        LianBiaoNode kuai = one.next.next;
        LianBiaoNode man = one.next;

        while (kuai != null && kuai.next != null) {
            System.out.println("begin================");
            System.out.println(kuai.i);
            System.out.println(man.i);
            System.out.println("over================");

            kuai = kuai.next.next;
            man = man.next;

            if (kuai == man) {
                System.out.println(kuai.i);
                break;
            }
        }

        System.out.println("================================");
        while (one != man) {

            System.out.println("start================");
            System.out.println(kuai.i);
            System.out.println(man.i);
            System.out.println("end================");

            one = one.next;
            man = man.next;

            if (one == man) {
                System.out.println(one.i);
                break;
            }
        }
    }
}
